package view;

import domein.FileSender;
import java.awt.BorderLayout;
import java.util.Observable;
import java.util.Observer;
import javax.swing.JButton;
import javax.swing.JFileChooser;
import javax.swing.JFrame;
import javax.swing.JPanel;
import javax.swing.JProgressBar;

/**
 *
 * @author Colin Bundervoet
 * @author Jeroen Pattyn
 */
public class FileSenderFrame  extends JFrame implements Observer {

    private FileSender fileSender;
    private JProgressBar progressbar;
    private JButton okButton;

    public FileSenderFrame(FileSender fileSender) {
        super("Sending File");
        this.fileSender = fileSender;
        progressbar = new JProgressBar();
        okButton = new JButton("OK");
        
        this.setSize(200, 100);
        this.setResizable(false);
        JPanel panel = new JPanel();
        panel.setLayout(new BorderLayout());
        panel.add(progressbar, BorderLayout.CENTER);
        panel.add(okButton, BorderLayout.SOUTH);
        okButton.setEnabled(false);
        this.add(panel);
        this.setLocationRelativeTo(null);
        this.setVisible(true);
        
        JFileChooser chooser = new JFileChooser("%USERPROFILE%");
        chooser.setFileSelectionMode(JFileChooser.FILES_ONLY);
        if(chooser.showOpenDialog(this) == JFileChooser.APPROVE_OPTION){
            fileSender.send(chooser.getSelectedFile());
        }
    }

    @Override
    public void update(Observable o, Object arg) {
        throw new UnsupportedOperationException("Not supported yet.");
    }
}
